package com.dormitory.myt.sushecontroller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dormitory.myt.common.R;
import com.dormitory.myt.en.Allsushe;
import com.dormitory.myt.service.AllsusheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/allsushe")
@Slf4j

public class AllsusheContorller {
    @Autowired
    AllsusheService allsusheService;

    //初始查询：
    @GetMapping()
    public R<Page> page1(HttpServletResponse response, @RequestParam int currentPage,@RequestParam int pageSize){
//        response.setHeader("Access-Control-Allow-Origin","*");
        //分页构造器
        Page<Allsushe> pageInfo = new Page<>(currentPage,pageSize);
        //条件构造器
        LambdaQueryWrapper<Allsushe> queryWrapper = new LambdaQueryWrapper<>();
        //分页查询
        allsusheService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }

    /**
     * 查询某栋楼：
     * @param response
     * @param currentPage
     * @param pageSize
     * @param dong
     * @return
     */
        @GetMapping("/select")
        public R<Page> page2(HttpServletResponse response, @RequestParam int currentPage,@RequestParam int pageSize,@RequestParam String dong){
            response.setHeader("Access-Control-Allow-Origin","*");
            //分页构造器
            Page<Allsushe> pageInfo = new Page<>(currentPage,pageSize);
            //条件构造器
            LambdaQueryWrapper<Allsushe> queryWrapper = new LambdaQueryWrapper<>();
            //模糊查询
            queryWrapper.like( Allsushe::getDong,dong);
            //分页查询
            allsusheService.page(pageInfo,queryWrapper);
            return R.success(pageInfo);
        }
}
